#!/bin/bash
#This script will create a zipped file that has all the history for the day.
#It will upload the data to a corresponding server

NOW=$(date +"%m%d%y-%T")
KIOSK="04"
FILE="history_"$KIOSK"_"$NOW

# Right now it is set to only dump the activity for the past 24 hours
# We could implement the kiosk to dump all the activity and completely remove all entries
echo "Getting the activity for the past 24 hours and dumping it to a file..."
sqlite3 history.db "select * from history where time between datetime('now','-1day') and datetime('now');" | gzip -c > $FILE.gz

#Now we would like to delete the history and start fresh every day with this command
#sqlite3 history.db "delete from history"

echo "Connecting to the server and putting the file in the correct location" 
ftp -in <<THEEND
open bayhawks.dreamhost.com
user grabillinois Gr@b@B1ke
cd kiosk/$KIOSK
put $FILE.gz
bye
THEEND

rm -f $FILE.gz
